package spring.boot.fusion.tools.response;

import java.io.Serializable;
import java.util.HashMap;
import org.springframework.http.HttpStatus;

import com.fasterxml.jackson.annotation.JsonInclude;

import lombok.Getter;
import lombok.Setter;
import spring.boot.fusion.tools.exception.ServiceErrorStatus;

@Setter
@Getter
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ResponseData<T> implements Serializable {

	private static final long serialVersionUID = 6688136731432037929L;
	private T data;
	private Integer status;
	private String message;
	private String describe;

	private ResponseData() {
	}

	private ResponseData(T data) {
		this.data = data;
	}

	private ResponseData(ServiceErrorStatus errorStatus) {
		this.status = errorStatus.status();
		this.message = errorStatus.message();
	}

	private ResponseData(Integer status, String message) {
		this.status = status;
		this.message = message;
	}

	private ResponseData(Integer status, String message, String describe) {
		this.status = status;
		this.message = message;
		this.describe = describe;
	}

	public static ResponseData<Object> SUCCESS() {
		ResponseData<Object> responseData = new ResponseData<>();
		responseData.setData(new HashMap<>());
		return responseData;
	}

	public static <T> ResponseData<T> SUCCESS(T data) {
		ResponseData<T> resultData = new ResponseData<>();
		resultData.setData(data);
		return resultData;
	}

	public static ResponseData<Object> ERROR(ServiceErrorStatus errorStatus) {
		return new ResponseData<>(errorStatus);
	}

	public static ResponseData<Object> ERROR(Integer status, String message) {
		return new ResponseData<>(status, message);
	}

	public static ResponseData<Object> ERROR(String message) {
		return new ResponseData<>(HttpStatus.BAD_REQUEST.value(), message);
	}
	
	public static ResponseData<Object> ERROR(Integer status, String message, String describe) {
		return new ResponseData<>(status, message, describe);
	}

}
